<template>
  <a-config-provider :locale="zh_CN">
    <div id="app">
      <router-view />
    </div>
  </a-config-provider>
</template>
<script>
import jwt_decode from 'jwt-decode'
import { isEmpty } from '@/utils/commonTools'
import zh_CN from 'ant-design-vue/lib/locale-provider/zh_CN';
import { initDynamicRoutes } from './router/index'
export default {
  name: 'app',
  created () {
    //每当组件发生加载时，就检测一下token是否存在，从而决定是否有认证，因为在响应拦截里设置了，如果token过期，就清除localstorage
    if (window.localStorage.getItem('NiuToken')) {
      const decode = jwt_decode(window.localStorage.getItem('NiuToken'))
      //根据token决定认证是true还是false
      this.$store.dispatch('setIsAuthenticated', !isEmpty(decode))
      this.$store.dispatch('setUser', decode)
    }
    //防止页面刷新，添加的动态路由消失
    initDynamicRoutes()
  },
  data () {
    return {
      zh_CN,
    }
  },
}
</script>

<style>
#app {
  width: 100%;
  height: 100%;
}
</style>
